package 天梯赛.A.A6;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        StringBuffer sb = new StringBuffer(str);
        int n = sc.nextInt();

        while (n-- > 0) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            String a = sc.next();
            String b = sc.next();
            //删除x-1
            //GreatWal
            String need = sb.substring(x - 1, y);
            sb = sb.delete(x - 1, y);
            String str2 = a + b;
            if (!sb.toString().contains(str2)) {
                sb.append(need);
            } else {
                //找到初始位置
                //初始位置
                //找第一个e的时候出现了问题
                int begin = sb.indexOf(str2)+a.length();
               // System.out.println(sb.toString());
                 sb= new StringBuffer(sb.substring(0, begin) +need+ sb.substring(begin));
            }
        }
        System.out.println(sb.toString());
    }
}
